package b.b.h;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.widget.ImageView;
import b.b.b;
import b.b.d.a.a;
import b.i.k.o;

/* compiled from: AppCompatImageHelper */
public class f {
    public final ImageView a;
    public d0 b;
    public d0 c;

    public f(ImageView imageView) {
        this.a = imageView;
    }

    public void a() {
        Drawable drawable = this.a.getDrawable();
        if (drawable != null) {
            o.b(drawable);
        }
        if (drawable != null) {
            d0 d0Var;
            int i = VERSION.SDK_INT;
            boolean z = true;
            Object obj = (i <= 21 && i == 21) ? 1 : null;
            if (obj != null) {
                if (this.c == null) {
                    this.c = new d0();
                }
                d0Var = this.c;
                d0Var.a = null;
                d0Var.d = false;
                d0Var.b = null;
                d0Var.c = false;
                ColorStateList imageTintList = this.a.getImageTintList();
                if (imageTintList != null) {
                    d0Var.d = true;
                    d0Var.a = imageTintList;
                }
                Mode imageTintMode = this.a.getImageTintMode();
                if (imageTintMode != null) {
                    d0Var.c = true;
                    d0Var.b = imageTintMode;
                }
                if (d0Var.d || d0Var.c) {
                    e.f(drawable, d0Var, this.a.getDrawableState());
                } else {
                    z = false;
                }
                if (z) {
                    return;
                }
            }
            d0Var = this.b;
            if (d0Var != null) {
                e.f(drawable, d0Var, this.a.getDrawableState());
            }
        }
    }

    public void b(AttributeSet attributeSet, int i) {
        int i2 = VERSION.SDK_INT;
        Context context = this.a.getContext();
        int[] iArr = b.f;
        f0 q = f0.q(context, attributeSet, iArr, i, 0);
        ImageView imageView = this.a;
        o.o(imageView, imageView.getContext(), iArr, attributeSet, q.b, i, 0);
        try {
            Drawable drawable = this.a.getDrawable();
            if (drawable == null) {
                int l = q.l(1, -1);
                if (l != -1) {
                    drawable = a.b(this.a.getContext(), l);
                    if (drawable != null) {
                        this.a.setImageDrawable(drawable);
                    }
                }
            }
            if (drawable != null) {
                o.b(drawable);
            }
            if (q.o(2)) {
                imageView = this.a;
                imageView.setImageTintList(q.c(2));
                if (i2 == 21) {
                    drawable = imageView.getDrawable();
                    if (!(drawable == null || imageView.getImageTintList() == null)) {
                        if (drawable.isStateful()) {
                            drawable.setState(imageView.getDrawableState());
                        }
                        imageView.setImageDrawable(drawable);
                    }
                }
            }
            if (q.o(3)) {
                imageView = this.a;
                imageView.setImageTintMode(o.c(q.j(3, -1), null));
                if (i2 == 21) {
                    drawable = imageView.getDrawable();
                    if (!(drawable == null || imageView.getImageTintList() == null)) {
                        if (drawable.isStateful()) {
                            drawable.setState(imageView.getDrawableState());
                        }
                        imageView.setImageDrawable(drawable);
                    }
                }
            }
            q.b.recycle();
        } catch (Throwable th) {
            q.b.recycle();
        }
    }

    public void c(int i) {
        if (i != 0) {
            Drawable b = a.b(this.a.getContext(), i);
            if (b != null) {
                o.b(b);
            }
            this.a.setImageDrawable(b);
        } else {
            this.a.setImageDrawable(null);
        }
        a();
    }

    public void d(ColorStateList colorStateList) {
        if (this.b == null) {
            this.b = new d0();
        }
        d0 d0Var = this.b;
        d0Var.a = colorStateList;
        d0Var.d = true;
        a();
    }

    public void e(Mode mode) {
        if (this.b == null) {
            this.b = new d0();
        }
        d0 d0Var = this.b;
        d0Var.b = mode;
        d0Var.c = true;
        a();
    }
}
